package com.itheima.controller;

import com.itheima.bean.Student;
import com.itheima.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateStudentServlet")
public class UpdateStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sid = req.getParameter("sid");
        String name = req.getParameter("name");
        Integer age = Integer.valueOf(req.getParameter("age"));

        Student stu = new Student(Integer.parseInt(sid),name,age);
        StudentService studentService = new StudentService();
        studentService.update(stu);

        resp.sendRedirect("/selectAllStudentServlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
